package com.cnfangmao.masterdata.common.response;

public class ResBody<T> {
	private Integer code;
	private String msg;
	private T data;

	public ResBody() {
	}

	public ResBody(Integer code, String msg) {
		this(code, msg, null);
	}

	public ResBody(Integer code, String msg, T data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public static ResBody<Object> success() {
		ResCodeEnum bizCode = ResCodeEnum.SUCCESS;
		return new ResBody<Object>(bizCode.getCode(), bizCode.getMessage());
	}

	public static ResBody<Object> success(Object data) {
		return success().data(data);
	}

	public static ResBody<Object> failure() {
		ResCodeEnum bizCode = ResCodeEnum.FAIL;
		return new ResBody<Object>(bizCode.getCode(), bizCode.getMessage());
	}

	public static ResBody<Object> failure(String message) {
		ResCodeEnum bizCode = ResCodeEnum.FAIL;
		return new ResBody<Object>(bizCode.getCode(), message);
	}

	public static ResBody<Object> custom(int code, String msg) {
		return new ResBody<Object>(code, msg);
	}

	public static ResBody<Object> custom(int code, String msg, Object data) {
		ResBody<Object> resBody = new ResBody<Object>(code, msg);
		resBody.data = data;
		return resBody;
	}

	public ResBody<T> message(String message) {
		this.msg = message;
		return this;
	}

	public ResBody<T> code(Integer code) {
		this.code = code;
		return this;
	}

	public ResBody<T> data(T data) {
		this.data = data;
		return this;
	}

	public Integer getCode() {
		return code;
	}

	public String getMsg() {
		return msg;
	}

	public T getData() {
		return data;
	}

	public static ResBody<Object> custom(BizCodeEnum<?> bizCodeEnum) {
		return custom(bizCodeEnum.getCode(), bizCodeEnum.getMessage());
	}
}
